package cate.game.play.proce.stat;

import cate.common.table.d.GDSkill;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

@NoteClass("战斗统计基础")
public abstract class StatBase {

	@NoteField("统计列表")
	public List<StatItem> stats =new ArrayList<>();

	public void add(StatItem stat) {
		for (StatItem item : stats) {
			if (item.eq(stat)) {
				item.value += stat.value;
				return;
			}
		}
		this.stats.add(stat.copy());
	}

	public long getTotalDamage(int actorPid) {
		return getTotalValue(actorPid, -1, GDSkill.StatType.DAMAGE);
	}

	public long getTotalHeal(int actorPid) {
		return getTotalValue(actorPid, -1, GDSkill.StatType.HEAL);
	}

	public long getTotalKill(int actorPid) {
		return getTotalValue(actorPid, -1, GDSkill.StatType.KILL);
	}

	public long getTotalHurt(int actorPid){ return getTotalValue(-1, actorPid, GDSkill.StatType.DAMAGE); }


	public long getTotalSkillDamage(int actorPid){
		return getTotalSkillDamage(actorPid, -1);
	}

	public long getTotalSkillDamage(int actorPid, int targetPid){
		return getTotalValue(actorPid, targetPid, GDSkill.StatType.SKILL_DAMAGE);
	}

	public long getTotalOverFlowSkillDamage(int actorPid, int targetPid){
		return getTotalValue(actorPid, targetPid, GDSkill.StatType.OVER_FLOW_DAMAGE);
	}


	public List<StatItem> findStats(Predicate<StatItem> predicate){
		List<StatItem> result = new ArrayList<>();
		for (StatItem stat : stats) {
			if(predicate.test(stat)){
				result.add(stat);
			}
		}
		return result;
	}


	public long getTotalValue(int actorPid, int targetPid, int type) {
		long totalValue = 0L;
		for (StatItem stat : stats) {
			if (actorPid > 0 && actorPid != stat.actorPid) {
				continue;
			}
			if (targetPid > 0 && targetPid != stat.targetPid) {
				continue;
			}
			if (stat.type != type) {
				continue;
			}
			totalValue += stat.value;
		}
		return totalValue;
	}

}
